package com.marketingexpert.service.snsmgnt.sina.weipan4j;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class Vdisk {
	
	private static String appKey = "75704290";
	private static String appsecret = "9538987364030bf5aae93f5959d355be";
	
	private static String username ="yuxingfirst@gmail.com"; 
	private static String password ="553002615";
	
	private static String HMACSHA1SignatureType = "HmacSHA1";
	
	private static String timestamp;
	
	public Vdisk() {
	} 
	
	public String getToken() {
		
		timestamp = generateTimeStamp();
		
		return null;
	}
	
	public String generateSignature(String params, String appsecret) {
		
		
		
	//	Mac mac = Mac.getInstance(HMACSHA1SignatureType);
		String oauthKey = encode(appsecret);
		//SecretKeySpec spec = new SecretKeySpec(oauthKey.getBytes("US-ASCII"), HMACSHA1SignatureType);
		//mac.init(spec);
		//oauthSignature = mac.doFinal(signatureBase.getBytes("US-ASCII"));
		return null;
		
	}
	
	public String generateTimeStamp() {
		return String.valueOf(System.currentTimeMillis() / 1000);
	}
	
	public static String encode(String value) {
		String encoded = null;
		try {
			encoded = URLEncoder.encode(value, "UTF-8");
		} catch (UnsupportedEncodingException ignore) {
		}
		StringBuffer buf = new StringBuffer(encoded.length());
		char focus;
		for (int i = 0; i < encoded.length(); i++) {
			focus = encoded.charAt(i);
			if (focus == '*') {
				buf.append("%2A");
			} else if (focus == '+') {
				buf.append("%20");
			} else if (focus == '%' && (i + 1) < encoded.length()
					&& encoded.charAt(i + 1) == '7'
					&& encoded.charAt(i + 2) == 'E') {
				buf.append('~');
				i += 2;
			} else {
				buf.append(focus);
			}
		}
		return buf.toString();
	}
	
}
